{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e0c8ebe4",
   "metadata": {},
   "source": [
    "## 方程推导结果："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ab3fe92",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7db94d25",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8ee07daf",
   "metadata": {},
   "source": [
    "## 方程推导结果："
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15989f58",
   "metadata": {},
   "source": [
    "$$\n",
    "(1/500+1/11000){v_1}-1/11000{v_2}-1/11000{v_3}=-1/200\\\\\n",
    "1/11000{v_1}-(1/1000+1/11000){v_2}+1/1000{v_3}=10^{-14}(e^{{v_2}/0.026}-1)\\\\\n",
    "-1/1000{v_1}-1/1000{v_2}+(1/500+1/11000){v_3}=1/2200\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24a5c660",
   "metadata": {},
   "source": [
    "### 对应函数：\n",
    "$$\n",
    "f_1(v_1,v_2,v_3)=(1/500+1/11000){v_1}-1/11000{v_2}-1/11000{v_3}+1/200\\\\\n",
    "f_2(v_1,v_2,v_3)=1/11000{v_1}-(1/1000+1/11000){v_2}+1/1000{v_3}-10^{-14}(e^{{v_2}/0.026}-1)\\\\\n",
    "f_3(v_1,v_2,v_3)=-1/1000{v_1}-1/1000{v_2}+(1/500+1/11000){v_3}-1/200\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1598fd9f",
   "metadata": {},
   "source": [
    "### 写出F（V）\n",
    "$$\n",
    "F(V)=\\begin{bmatrix}\n",
    "(1/500+1/11000){v_1}-1/11000{v_2}-1/11000{v_3}+1/200\\\\\n",
    "1/11000{v_1}-(1/1000+1/11000){v_2}+1/1000{v_3}-10^{-14}(e^{{v_2}/0.026}-1)\\\\\n",
    "-1/1000{v_1}-1/1000{v_2}+(1/500+1/11000){v_3}-1/200\n",
    "\\end{bmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4363c09f",
   "metadata": {},
   "source": [
    "### 写出DF（x）\n",
    "$$\n",
    "DF(V)=\\begin{bmatrix}\n",
    "1/500+1/11000&-1/11000&-1/11000\\\\\n",
    "1/11000&-1/1000-1/11000-3.84615384615×10^{-13}e^{{v_2}/0.026}&1/1000\\\\\n",
    "-1/1000&-1/1000&1/500+1/11000\n",
    "\\end{bmatrix}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "ccb67bd0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "id": "1309f3b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "def F(V):\n",
    "    f1=(1/500+1/11000)*V[0]-1/11000*V[1]-1/1000*V[2]+1/200\n",
    "    f2=1/11000*V[0]-(1/1000+1/11000)*V[1]+1/1000*V[2]-5.95*10**(-6)*(2.718281828459**(V[1]/9.582)-1)\n",
    "    f3=-1/1000*V[0]-1/1000*V[1]+(1/500+1/11000)*V[2]-1/200\n",
    "    return np.array([f1,f2,f3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "e355afac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.00390909,  0.00090771, -0.00172727])"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Vold=np.array([1,2,3])\n",
    "F(Vold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "bb7163e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "def DF(V):\n",
    "    df11=1/500+1/11000\n",
    "    df12=-1/11000\n",
    "    df13=-1/1000\n",
    "    df21=1/11000\n",
    "    df22=-1/1000-1/11000-6.21*10**(-7)*(2.718281828459)**(V[1]/0.026)\n",
    "    df23=1/1000\n",
    "    df31=-1/1000\n",
    "    df32=-1/1000\n",
    "    df33=1/500+1/11000\n",
    "    return np.array([[df11,df12,df13],\n",
    "                    [df21,df22,df23],\n",
    "                    [df31,df32,df33]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "0cb0d418",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2.09090909e-03, -9.09090909e-05, -1.00000000e-03],\n",
       "       [ 9.09090909e-05, -3.13852447e+10,  1.00000000e-03],\n",
       "       [-1.00000000e-03, -1.00000000e-03,  2.09090909e-03]])"
      ]
     },
     "execution_count": 174,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Vold=np.array([1,1,1])\n",
    "DF(Vold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "id": "035f7b3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def calVnew(V):\n",
    "    s=np.linalg.inv(DF(V))@F(V)\n",
    "    Vnew=V-s\n",
    "    return Vnew"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "970e9e1c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.706622824128787\n",
      "第 1 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "2.311115933264683e-31\n",
      "第 2 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "9.14174746935808e-32\n",
      "第 3 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "9.14174746935808e-32\n",
      "第 4 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 5 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 6 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 7 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 8 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 9 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 10 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 11 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 12 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 13 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 14 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 15 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 16 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 17 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 18 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 19 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 20 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 21 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 22 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 23 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 24 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 25 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 26 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 27 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 28 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 29 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 30 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 31 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 32 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 33 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 34 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 35 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 36 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 37 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 38 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 39 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 40 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 41 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 42 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 43 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 44 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 45 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 46 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 47 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 48 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 49 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 50 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 51 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 52 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 53 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 54 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 55 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 56 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 57 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 58 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 59 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 60 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 61 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 62 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 63 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 64 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 65 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 66 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 67 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 68 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 69 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 70 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 71 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 72 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 73 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 74 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 75 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 76 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 77 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 78 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 79 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 80 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 81 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 82 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 83 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 84 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 85 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 86 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 87 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 88 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 89 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 90 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 91 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 92 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 93 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 94 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 95 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 96 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 97 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 98 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n",
      "4.642775119269496e-31\n",
      "第 99 次迭代 \tVnew [-0.35904101  3.56605046  3.92509147]\n"
     ]
    }
   ],
   "source": [
    "Vold=np.array([1,0,1])\n",
    "for i in range(1,100):\n",
    "    Vnew=calVnew(Vold)\n",
    "    stdError=np.square(Vnew-Vold).mean()\n",
    "    print(stdError)\n",
    "    Vold=Vnew\n",
    "    print(\"第\",i,\"次迭代\",\"\\tVnew\",Vnew)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1bd0c3d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "503166ba",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
